package 面向对象高级.内部类.成员内部类;

public class TestMemberInnerClass {
    public static void main(String[] args) {
        /**
         * 外部类名.静态内部类名 变量 = 外部类名.静态内部类名();
         * 变量.非静态方法();
         */
        Outer.StaticInner inner1 = new Outer.StaticInner();
        inner1.inMethod();
        inner1.inFun();
    }
}

class Outer {
    private static String a = "外部类的静态类a";
    private static String b = "外部类的静态类b";
    private String c = "外部类的非静态c";
    private String d = "外部类的非静态d";

    //静态内部类
    static class StaticInner {
        private static String a = "我是静态内部类的静态a";
        private String c = "我是静态内部类的非静态c";

        //静态方法
        public static void inMethod() {
            System.out.println(a);
            System.out.println(Outer.a);
            System.out.println(b);
            //d在外部为非静态的，所以在静态方法中访问不到
            //System.out.println(d);
        }

        public void inFun() {
            System.out.println(a);
            System.out.println(Outer.a);
            System.out.println(b);
            System.out.println(c);
            //System.out.println(d);
        }
    }

    //非静态内部类
    class NoStaticInner {
        private String a = "非静态内部类对象的非静态a";
        private String c = "非静态内部类对象的非静态c";

        public void inFun() {
            System.out.println("NoStaticInner.inFun");
            System.out.println("Outer.a = " + Outer.a);
            System.out.println("a = " + a);
            System.out.println("b = " + b);
            System.out.println("Outer.c = " + Outer.this.c);
            System.out.println("c = " + c);
            System.out.println("d = " + d);
            //System.out.println(d);
        }

        public NoStaticInner getNoSaticInner() {
            return new NoStaticInner();
        }
    }
}
